/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.shape;

import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;


/**
*A class representing a shape function for the T4 tetrahedral element.
*
*@author Lucas, Marcelo & Pitangueira, Roque
*@version 1.0
*@since August 2004
*/

public class Tetra4 extends ShapeC0 
{
	private static final long serialVersionUID = 1L;

	/** Returns the IVector containing the values of shape function evalueted in provided points.
	*@param g The vector containing the coordinates which the shape function will be evalueted.
	*@param cN The matrix containing nodal coordinates in cartesian system.
	*@return The IVector containing the values of shape function evalueted in provided points.
	*/
	public IVector getShapeFunction(double[] g, IMatrix cN) 
	{
		double a = g[0];
		double b = g[1];
		double c = g[2];
	
		IVector n = new IVector(4);
		
		double n0 = (1-a-b-c);
		double n1 = (a);
		double n2 = (b);
		double n3 = (c);

		n.setElement(0,n0);
		n.setElement(1,n1);
		n.setElement(2,n2);
		n.setElement(3,n3);
		
		return (n);
	}
	
	/** Returns the IMatrix containing the values of shape function derived in xi and eta evalueted in provided points.
	*@param g The vector containing the coordinates which the shape function will be evalueted.
	*@param cN The matrix containing nodal coordinates in cartesian system.
	*@return The IMatrix containing the values of shape function derived in xi and eta evalueted in provided points.
	*/
	public IMatrix getDerivedShapeFunction(double[] g, IMatrix cN) 
	{
		IMatrix dl = new IMatrix(3,4);
		
	//derivadas em relacao a xi (a = xi e b = eta e c = zeta)
		double dl0 = (-1);
		double dl1 = (1);
		double dl2 = (0);
		double dl3 = (0);
	//derivadas em relacao a eta (a = xi e b = eta e c = zeta)
		double dl4 = (-1);
		double dl5 = (0);
		double dl6 = (1);
		double dl7 = (0);
	//derivadas em relacao a zeta (a = xi e b = eta e c = zeta)
		double dl8 = (-1);
		double dl9 = (0);
		double dl10 = (0);
		double dl11 = (1);
		
	//derivadas em relacao a xi na linha 0 da IMatrix
		dl.setElement(0,0,dl0);
		dl.setElement(0,1,dl1);
		dl.setElement(0,2,dl2);
		dl.setElement(0,3,dl3);
	//derivadas em relacao a eta na linha 1 da IMatrix
		dl.setElement(1,0,dl4);
		dl.setElement(1,1,dl5);
		dl.setElement(1,2,dl6);
		dl.setElement(1,3,dl7);
	//derivadas em relacao a zeta na linha 2 da IMatrix
		dl.setElement(2,0,dl8);
		dl.setElement(2,1,dl9);
		dl.setElement(2,2,dl10);
		dl.setElement(2,3,dl11);
		
		return (dl);
	}
	
	/** Return the IMatrix containing nodal coordinates of this shape in natural system.
	*@return natCoords The IMatrix with nodal coordinates of this shape in natural system.
	*/
	public IMatrix getNaturalNodalCoords()
	{
		
		IMatrix natCoords = new IMatrix(3,4);
		
	//coordenadas naturais de xi
		natCoords.setElement(0,0,1);
		natCoords.setElement(0,1,0);
		natCoords.setElement(0,2,0);
		natCoords.setElement(0,3,0);
	//coordenadas naturais de eta
		natCoords.setElement(1,0,0);
		natCoords.setElement(1,1,1);
		natCoords.setElement(1,2,0);
		natCoords.setElement(1,3,0);
	//coordenadas naturais de zeta
		natCoords.setElement(2,0,0);
		natCoords.setElement(2,1,0);
		natCoords.setElement(2,2,1);
		natCoords.setElement(2,3,0);
		
			return natCoords;
	}

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.shape.Shape3D#getType()
     */
    public String getType() {
        return "Tetra4";
    }
	
}

